package com.ny.zmb.openapi.controller;

import com.ny.zmb.openapi.entity.PmCloudstore;
import com.ny.zmb.openapi.jh.from.CategoryVo;
import com.ny.zmb.openapi.jh.service.JHCategoryService;
import com.ny.zmb.openapi.mapper.PmCloudStoreMapper;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@SpringBootTest
public class JHClassifierController {

    @Resource
    private PmCloudStoreMapper pmCloudStoreMapper;
    @Test
    public void insert(){
        long l = System.currentTimeMillis();
        Long nowTime = l / 1000;
        BigDecimal zero = BigDecimal.ZERO;
        List<CategoryVo> category = JHCategoryService.category(null);
        for (CategoryVo vo : category) {
            insertToClass(vo,zero,nowTime);
            List<CategoryVo> category1 = JHCategoryService.category(vo.getCatId());
            for (CategoryVo categoryVo : category1) {
                insertToClass(categoryVo,zero,nowTime);
                List<CategoryVo> category2 = JHCategoryService.category(categoryVo.getCatId());
                for (CategoryVo categoryVo1 : category2) {
                    insertToClass(categoryVo1,zero,nowTime);
                }
            }
        }

    }

    public void insertToClass (CategoryVo vo,BigDecimal zero,Long nowTime){
        PmCloudstore build = PmCloudstore.builder()
                .id(vo.getCatId())
                .name(vo.getName())
                .icon(vo.getCatLogo())
                .addTime(nowTime.intValue())
                .mark("")
                .status(1)
                .updateTime(0)
                .fee(zero)
                .dayLimit(0)
                .yeji(zero)
                .storeId(0)
                .userId(0)
                .type(0)
                .endTime(0)
                .param("")
                .pid(vo.getParentId())
                .build();
        pmCloudStoreMapper.insert(build);
    }
}
